<template>
	<div id="container">
		<div id="search_content">
			<el-form ref="search_form" label-width="120px">
				<el-form-item label="咨询师姓名:">
					<el-input v-model="con.consultName">
						<template #prepend>
							<i class="el-icon-user" style="font-size: 20px;"></i>
						</template>
					</el-input>
				</el-form-item>
				<el-form-item label="咨询师账号:">
					<el-input v-model="con.consultId">
						<template #prepend>
							<i class="el-icon-notebook-2" style="font-size: 20px;"></i>
						</template>
					</el-input>
				</el-form-item>
				<el-form-item label="咨询师状态:">
					<el-input v-model="con.consultStatus">
						<template #prepend>
							<i class="el-icon-eleme" style="font-size: 20px;"></i>
						</template>
					</el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="el-icon-search" v-on:click="search()">
						查询
					</el-button>
				</el-form-item>
			</el-form>
		</div>

		<div id="show_content">
			<div id="show_table">
				<el-table :data="consults" border style="width: 100%" @selection-change="handleSelectionChange"
					:header-cell-style="{textAlign: 'center'}" :cell-style="{ textAlign: 'center' }">
					<el-table-column type="selection"></el-table-column>
					<el-table-column label="咨询师姓名" prop="consultName"></el-table-column>
					<el-table-column label="咨询师账号" prop="consultId"></el-table-column>
					<el-table-column label="咨询师状态" prop="consultStatus"></el-table-column>
					<el-table-column fixed="right" label="操作">
						<template #default="scope">
							<el-button type="primary" class="el-icon-delete" @click="del(scope.row)">删除</el-button>
						</template>
					</el-table-column>
				</el-table>
			</div>
			<div id="page_content">
				<el-pagination 
				background layout="prev,pager,next" 
				:total="pageTotle" 
				:page-size="pageSize"
				@current-change="pageData">
				</el-pagination>
			</div>
		</div>
		
	</div>
</template>

<script>
	export default {
		name: 'consultAdmin',
		data() {
			return {
				con: {
					consultName: '',
					consultId: '',
					consultStatus: '',
				},
				multipleSelection: [],
				consults: [],
				pageNum: 1,
				pageTotle: 0,
				pageSize: 4
				//search:''
			}
		},
		methods: {
			init() {
				this.con.pageNum = this.pageNum;
				this.con.pageSize = this.pageSize;
				var param = this.$qs.stringify(this.con);
				this.$axios
					.post("consult/findByParam", param)
					.then(rst => {
						console.log(rst);
						this.consults = rst.data.list;
						this.pageTotle = rst.data.total;
					}).catch(ex => {
						console.log(ex);
					});
			},
			search() {
				this.pageNum = 1;
				this.init();
			},
			del(row){
			    this.$confirm('此操作将永久删除, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(()=>{
					let param={
						consultId : row.consultId
					}
					let data = this.$qs.stringify(param);
					// console.log(data);
					this.$axios
					.post("consult/dofindByConsultId",data)
					.then(rst=>{
						//console.log(rst.data);
						if(rst.data==0){
							this.$axios
							.post("consult/doDelete",data)
							.then(res=>{
								this.init();
							})
						}
						else{
							this.$message({
								type:'info',
								message:'该咨询师下还有学生，无法删除'
							});
						}
					}).catch(()=>{
						// this.$message({
						// 	type:'info',
						// 	message:'该咨询师下还有学生，无法删除'
						// });
					});
				}).catch(()=>{
					this.$message({
						type:'info',
						message:'已取消删除'
					});
				});
			},
			handleSelectionChange(val) {
				this.multipleSelection = val;
				console.log(this.multipleSelection)
			},
			pageData(curr) {
				this.pageNum = curr;
				this.init();
		    }	
		}
	}
</script>

<style>
</style>

